package com.ruoyi.workSafetyStandardization.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.workSafetyStandardization.mapper.MajorConfigMapper;
import com.ruoyi.workSafetyStandardization.service.IMajorConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.workSafetyStandardization.mapper.StandardConfigMapper;
import com.ruoyi.workSafetyStandardization.domain.StandardConfig;
import com.ruoyi.workSafetyStandardization.service.IStandardConfigService;

/**
 * 标准配置Service业务层处理
 *
 * @author hcc
 * @date 2023-12-14
 */
@Service
public class StandardConfigServiceImpl implements IStandardConfigService
{
    @Autowired
    private StandardConfigMapper standardConfigMapper;
    @Autowired
    private MajorConfigMapper majorConfigMapper;
    @Autowired
    private IMajorConfigService majorConfigService;

    /**
     * 查询标准配置
     *
     * @param standardId 标准配置主键
     * @return 标准配置
     */
    @Override
    public StandardConfig selectStandardConfigByStandardId(String standardId)
    {
        return standardConfigMapper.selectStandardConfigByStandardId(standardId);
    }

    /**
     * 查询标准配置列表
     *
     * @param standardConfig 标准配置
     * @return 标准配置
     */
    @Override
    public List<StandardConfig> selectStandardConfigList(StandardConfig standardConfig)
    {
        return standardConfigMapper.selectStandardConfigList(standardConfig);
    }

    /**
     * 新增标准配置
     *
     * @param standardConfig 标准配置
     * @return 结果
     */
    @Override
    public int insertStandardConfig(StandardConfig standardConfig)
    {
        standardConfig.setCreateByName(SecurityUtils.getUsername());
        standardConfig.setCreateAt(new Date());
        standardConfig.setCreateBy(SecurityUtils.getUserId().toString());
        return standardConfigMapper.insertStandardConfig(standardConfig);
    }

    /**
     * 修改标准配置
     *
     * @param standardConfig 标准配置
     * @return 结果
     */
    @Override
    public int updateStandardConfig(StandardConfig standardConfig)
    {
        return standardConfigMapper.updateStandardConfig(standardConfig);
    }

    /**
     * 批量删除标准配置
     *
     * @param standardIds 需要删除的标准配置主键
     * @return 结果
     */
    @Override
    public int deleteStandardConfigByStandardIds(String[] standardIds)
    {
        return standardConfigMapper.deleteStandardConfigByStandardIds(standardIds);
    }

    /**
     * 删除标准配置信息
     *
     * @param standardId 标准配置主键
     * @return 结果
     */
    @Override
    public int deleteStandardConfigByStandardId(String standardId)
    {
        return standardConfigMapper.deleteStandardConfigByStandardId(standardId);
    }

    @Override
    public List<StandardConfig> listWithTree() {
        return null;
    }

    /**
     * 查找列表
     *
     * @param ids 包含ItemId或MajorId
     * @return list
     */

    @Override
    public List<StandardConfig> selectStandardConfigByItemIdAndMajorId(String[] ids) {
        if ("".equals(ids[0]) || ids[0]==null){
            return standardConfigMapper.queryAll();
        }else {
            if ("".equals(ids[1]) ||  ids[1]==null){
                return standardConfigMapper.selectStandardConfigByMajorId(ids[0]);
            }else {
                StandardConfig standardConfig=new StandardConfig();
                standardConfig.setMajorId(ids[0]);
                standardConfig.setItemId(ids[1]);
                return standardConfigMapper.selectStandardConfigByItemIdAndMajorId(standardConfig);
            }
        }

    }

    @Override
    public List<StandardConfig> queryStandardByMajorId(String majorId) {
        return standardConfigMapper.queryStandardByMajorId(majorId);
    }

    @Override
    public List<StandardConfig> queryStandardByItemId(String itemId) {
        return standardConfigMapper.queryStandardByItemId(itemId);
    }

    @Override
    public List<StandardConfig> queryStandardByMajorIdAndEnable(StandardConfig standardConfig) {
        return standardConfigMapper.queryStandardByMajorIdAndEnable(standardConfig);
    }

    @Override
    public List<StandardConfig> getOneItem(String itemId) {
        return standardConfigMapper.getOneItem(itemId) ;
    }

}
